﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Beetle.Sl.EditorControl.Core;

namespace Beetle.Sl.EditorControl.ToolBars
{
    public abstract class TextAlignmentToolBar : ToolBarItem
    {
        public abstract TextAlignment TextAlignment
        {
            get;
        }

        protected string CommandText
        {
            get
            {
                // return "TextAlignment" + this.TextAlignment.ToString();
                return "SetFontStyle";
            }
        }

        public TextAlignmentToolBar()
        {
            this.ImageButtonUri = new Uri(string.Format("/Beetle.Sl.EditorControl;component/ToolBars/TextAlignment{0}/{0}.png", this.TextAlignment.ToString()), UriKind.Relative);
        }

        public override void OnCommand(object arg)
        {
            if (this.IsEnabled)
            {
                this.Editor.ExcuteCommand(this.CommandText, new object[] { Paragraph.TextAlignmentProperty, this.TextAlignment });
            }
        }

        public override void UpdateVisual()
        {
            this.IsEnabled = !this.Editor.RichTextBoxInst.IsReadOnly;
            if (this.IsEnabled)
            {
                object obj = this.Editor.RichTextBoxInst.Selection.GetPropertyValue(Paragraph.TextAlignmentProperty);

                if (obj != null && obj is TextAlignment)
                {
                    this.IsSelected = ((TextAlignment)obj == this.TextAlignment);
                }
            }
            else
            {
                this.IsSelected = false;
            }
        }
    }
}
